package com.etone.smartAudit.controller;


import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.domain.ProjectFile;
import com.etone.smartAudit.service.ProjectFileCollectService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.projectFile.ProjectFileDirVO;
import com.etone.smartAudit.vo.projectFile.ProjectFileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 * 文件收藏表 文件收藏表 前端控制器
 * </p>
 *
 * @author jiayen
 * @since 2021-05-08
 */
@RestController
@Api(tags = "项目文件收藏", value = "项目文件收藏")
public class ProjectFileCollectController {

    @Autowired
    private ProjectFileCollectService collectService;

    @ApiOperation(value = "执行文件收藏", tags = "jiayen")
    @PostMapping("/project/file/collect/{fId}")
    public void collectFile(@ApiIgnore @LoginAdmin Admin admin, @ApiParam("文件id") @PathVariable Integer fId) {
        collectService.collectFile(admin, fId);
    }

    @ApiOperation(value = "执行文件取消收藏", tags = "jiayen")
    @PostMapping("/project/file/cancleCollect/{fId}")
    public void cancleCollect(@ApiIgnore @LoginAdmin Admin admin, @ApiParam("文件id") @PathVariable Integer fId) {
        collectService.cancleCollect(admin, fId);
    }

    @ApiOperation(value = "当前登录用户收藏文件列表树", tags = "jiayen")
    @PostMapping("/project/file/collectList")
    public ProjectFileDirVO collectList(@ApiIgnore @LoginAdmin Admin admin) {
        return collectService.collectList(admin);
    }


    @ApiOperation(value = "当前登录用户收藏文件夹下的列表", tags = "jiayen")
    @PostMapping("/project/file/collectFiles/{pId}")
    public PagerVO<ProjectFileVO> collectFiles(@ApiIgnore @LoginAdmin Admin admin, @ApiParam("文件夹id") @PathVariable Integer pId,
                                               @ApiParam(value = "项目id") @RequestParam(required = false, defaultValue = "1") int projectId,
                                               @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
                                               @ApiParam(value = "文件名称，搜索使用可以不传") @RequestParam(required = false) String fileName,
                                               @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize) {
        return collectService.collectFiles(admin, pId, page, pageSize, projectId,fileName);
    }


}
